#!/bin/sh
#
# PX4 FMUv6X specific board sensors init
#------------------------------------------------------------------------------
set HAVE_PM2 yes

if ver hwtypecmp V6X005000 V6X005001 V6X005003 V6X005004
then
	set HAVE_PM2 no
fi
if param compare -s ADC_ADS1115_EN 1
then
	ads1115 start -X
else
	board_adc start
fi


if param compare SENS_EN_INA226 1
then
	# Start Digital power monitors
	ina226 -X -b 1 -t 1 -k start

	if [ $HAVE_PM2 = yes ]
	then
		ina226 -X -b 2 -t 2 -k start
	fi
fi

if param compare SENS_EN_INA228 1
then
	# Start Digital power monitors
	ina228 -X -b 1 -t 1 -k start
	if [ $HAVE_PM2 = yes ]
	then
		ina228 -X -b 2 -t 2 -k start
	fi
fi

if param compare SENS_EN_INA238 1
then
	# Start Digital power monitors
	ina238 -X -b 1 -t 1 -k start
	if [ $HAVE_PM2 = yes ]
	then
		ina238 -X -b 2 -t 2 -k start
	fi
fi


if ver hwtypecmp V6X000004 V6X001004 V6X004004 V6X005004
then
	# Internal SPI bus ICM20649
	icm20649 -s -R 6 start
else
	# Internal SPI BMI088
	if ver hwtypecmp V6X009010 V6X010010
	then
		bmi088 -A -R 6 -s start
		bmi088 -G -R 6 -s start
	else
		if ver hwtypecmp V6X000010
		then
			bmi088 -A -R 0 -s start
			bmi088 -G -R 0 -s start
		else
			bmi088 -A -R 4 -s start
			bmi088 -G -R 4 -s start
		fi
	fi
fi

# Internal SPI bus ICM42688p
if ver hwtypecmp V6X009010 V6X010010
then
	icm42688p -R 12 -s start
else
	if ver hwtypecmp V6X000010
	then
		icm42688p -R 14 -s start
	else
		icm42688p -R 6 -s start
	fi
fi

if ver hwtypecmp V6X000003 V6X001003 V6X003003 V6X000004 V6X001004 V6X004003 V6X004004 V6X005003 V6X005004
then
	# Internal SPI bus ICM-42670-P (hard-mounted)
	icm42670p -R 10 -s start
else
	if ver hwtypecmp V6X009010 V6X010010
	then
		icm20602 -R 6 -s start
	else
		# Internal SPI bus ICM-20649 (hard-mounted)
		icm20649 -R 14 -s start
	fi
fi

# Internal magnetometer on I2c
if ver hwtypecmp V6X002001
then
	rm3100 -I -b 4 start
else
	if ver hwtypecmp V6X009010 V6X010010
	then
		# Internal magnetometer on I2C
		bmm150 -I -R 0 start
	else
		bmm150 -I -R 6 start
	fi
fi

# External compass on GPS1/I2C1 (the 3rd external bus): standard Holybro Pixhawk 4 or CUAV V5 GPS/compass puck (with lights, safety button, and buzzer)
ist8310 -X -b 1 -R 10 start

# Possible internal Baro
if param compare SENS_INT_BARO_EN 1
then
	if ver hwtypecmp V6X002001
	then
		icp201xx -I -a 0x64 start
	else
		bmp388 -I -a 0x77 start
	fi
fi

#external baro
if ver hwtypecmp V6X002001
then
	icp201xx -X start
else
	bmp388 -X start
fi

# Baro on I2C3
ms5611 -X start

unset HAVE_PM2
